local HcLogic = require("refine.HcLogic")
local QhLogic = require("refine.QhLogic")
local XlLogic = require("refine.XlLogic")
local XqLogic = require("refine.XqLogic")
local SjLogic = require("refine.SjLogic")
local TpLogic = require("refine.TpLogic")
local Msg = require("core.Msg")
local needItemConfig = require("excel.Strength").other

--选择装备
function CG_CHOOSE_EQUIP(human, msg)
  if msg.type == 1 then
    QhLogic.chooseEquip(human, msg.index)
  elseif msg.type == 2 then
    SjLogic.chooseEquip(human, msg.index)
  elseif msg.type == 3 then
    TpLogic.chooseEquip(human, msg.index)
  elseif msg.type == 4 then
    XlLogic.chooseEquip(human, msg.index)
  end
end

--打开界面
function CG_EQUIP_OPEN(human, msg)
  if msg.type == 1 then
    QhLogic.open(human)
  elseif msg.type == 2 then
    SjLogic.open(human)
  elseif msg.type == 3 then
    TpLogic.open(human)
  end
end
--升阶
function CG_EQUIP_SHENGJIE(human, msg)
  SjLogic.shengjie(human, msg.index)
end
--提品
function CG_EQUIP_TIPIN(human, msg)
  TpLogic.tipin(human, msg.index, msg.isAutoBuy)
end
--强化
function CG_EQUIP_STRENGTH(human, msg)
  QhLogic.Strength(human, msg.index, msg.succRune, msg.isAutoBuy)
end
--镶嵌
function CG_EQUIP_XIANQIANG(human, msg)
  XqLogic.Xiangqiang(human, msg.index, msg.gemPos, msg.gemIndex)
end
function CG_EQUIP_PUTOFF_STONE(human, msg)
  XqLogic.putOff(human, msg.index, msg.gemIndex)
end
--洗练
function CG_EQUIP_XILIAN(human, msg)
  XlLogic.xilian(human, msg.isAutoBuy, msg.index)
end
--保存洗练属性
function CG_EQUIP_XILIAN_SAVE(human, msg)
  XlLogic.save(human, msg.index)
end

--合成
function CG_HECHENG_ITEM(human, msg)
  HcLogic.hecheng(human, msg.index, msg.cnt)
end

--得到合成配置表
function CG_GET_HECHENG_CONFIG(human)
  HcLogic.getConfig(human)
end
--锻造面板感叹号显示
function CG_OPEN_REFINE_WINDOW(human)
  local sendMsg = Msg.gc.GC_REFINE_TIPS
  sendMsg.info[0] = 5
  sendMsg.info[1].equip[0] = 0
  sendMsg.info[1].isShow = SjLogic.checkShowTips(human, sendMsg.info[1])
  sendMsg.info[1].index = 1
  sendMsg.info[2].equip[0] = 0
  sendMsg.info[2].isShow = TpLogic.checkShowTips(human, sendMsg.info[2])
  sendMsg.info[2].index = 2
  sendMsg.info[3].equip[0] = 0
  sendMsg.info[3].isShow = XqLogic.checkShowTips(human, sendMsg.info[3])
  sendMsg.info[3].index = 3
  sendMsg.info[4].equip[0] = 0
  sendMsg.info[4].isShow = XlLogic.checkShowTips(human, sendMsg.info[4])
  sendMsg.info[4].index = 4
  sendMsg.info[5].equip[0] = 0
  sendMsg.info[5].isShow = QhLogic.checkShowTips(human, sendMsg.info[5])
  sendMsg.info[5].index = 5
--  local isChange = false
--  for i=1, sendMsg.info[0] do
--    if sendMsg.info[i].isShow ~= 0 then
--      isChange = true
--      sendFunctionTips(human, 1)
--    end
--  end
--  if not isChange then
--    sendFunctionTips(human, 0)
--  end
  Msg.send(sendMsg, human.fd)
end
--主界面锻造界面是否显示感叹号
function sendFunctionTips(human, isShow)
  local sendMsg = Msg.gc.GC_ROLE_FUNCTION_TIPS
  sendMsg.isShow = isShow or 1
  if SjLogic.checkShowTips(human) == 0 and not isShow then
    if TpLogic.checkShowTips(human) == 0 then
      if XqLogic.checkShowTips(human) == 0 then
        if XlLogic.checkShowTips(human) == 0 then
          sendMsg.isShow = 0
        end
      end
    end
  end
  Msg.send(sendMsg, human.fd)
  checkIsRight(human)
end

function checkIsRight(human)
  if human.db.xlLv[0].lv ~= 0 then
    return
  end
  for i=0, human.db.xlLvLen - 1 do
    human.db.xlLv[i].lv = 1
  end
end

function CG_REFINE_ITEM_CHANGE(human)
  CG_OPEN_REFINE_WINDOW(human)
end

function isRefineItem(id)
  for i=1, #needItemConfig[1].itemList do
    if id == needItemConfig[1].itemList[i] then
      return true
    end
  end
  return false
end